<?php
/**
 * @title 343. 整数拆分 - 数学
 * @author start2004
 */


class Solution {

    /**
     * @param Integer $n
     * @return Integer
     */
    function integerBreak($n) {
        /**
         * @since 2020-07-30 特殊情况处理
         */
        if($n == 2){
            return 1;
        } elseif($n == 3) {
            return 2;
        }

        /**
         * @since 2020-07-30 取模
         */
        $m = $n%3;
        $count3 = intval($n/3);

        /**
         * @since 2020-07-30 取模决定2的数量
         */
        switch ($m){
            case 0:
                /**
                 * @since 2020-07-30 0个2
                 */
                $result = pow(3, $count3);
                break;
            case 1:
                /**
                 * @since 2020-07-30 2个2
                 */
                $result = pow(3, $count3-1)*4;
                break;
            case 2:
                /**
                 * @since 2020-07-30 1个2
                 */
                $result = pow(3, $count3)*2;
                break;
            default:
                $result = false;
        }

        /**
         * @return
         */
        return $result;
    }
}



/**
 * @url http://127.0.0.1/leetcode/202007/2020.07.30.php
 */
$datas = [
    10,
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->integerBreak($data);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
